/*
 * @FileDescription:
 * @Author: wangzhichiao<https://github.com/wzc570738205>
 * @Date: 2021-11-26 09:39:26
 * @LastEditors: wangzhichiao<https://github.com/wzc570738205>
 * @LastEditTime: 2021-11-26 11:11:07
 */
import { defineStore } from "pinia";

// main is the name of the store. It is unique across your application
// and will appear in devtools
export const useMainStore = defineStore("main", {
  // a function that returns a fresh state
  state: () => ({
    counter: 10,
    name: "Eduardo",
  }),
  // optional getters
  getters: {
    // getters receive the state as first parameter
    getCount: (state) => state.counter,
    doubleCount: (state) => state.counter * 2,
    // use getters in other getters
    doubleCountPlusOne() {
      return this.doubleCount * 2 + 1;
    },
  },
  // optional actions
  actions: {
    reset() {
      // `this` is the store instance
      this.counter = 0;
    },
    addCount() {
      // `this` is the store instance
      this.counter += 1;
      console.log('this.counter: ', this.counter);
    },
  },
});
